﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CrossQuery.ConditionQuery
{
    public class DateCondition : Condition
    {
        protected string database_name;
        protected string table_name;
        protected string field_name;

        protected string start_date, end_date;

        public DateCondition() { }

        public DateCondition(string database, string table, string field)
        {
            database_name = database;
            table_name = table;
            field_name = field;
        }

        public string Database
        {
            get { return database_name; }
            set { database_name = value; }
        }

        public string Table
        {
            get { return table_name; }
            set { table_name = value; }
        }

        public string Field
        {
            get { return field_name; }
            set { field_name = value; }
        }
        public string Type { get { return "Date"; } }

        /// <summary>
        /// Start Date of This Date Condition
        /// </summary>
        public string StartDate
        {
            get { return start_date; }
            set { start_date = value; }
        }

        /// <summary>
        /// End Date of This Date Condition
        /// </summary>
        public string EndDate
        {
            get { return end_date; }
            set { end_date = value; }
        }

        public string ToSQLString()
        {
            if (start_date == null || end_date == null || start_date == "" || end_date == "")
                return "true";
            string left = String.Format(" `{0}`.`{1}`", table_name, field_name);
            return " " + left + ">='" + start_date + "' and " + left + "<='" + end_date + "' ";
        }
    }
}
